package gamagora.game.entity
{
	
	import gamagora.game.entity.OSSound;
	import gamagora.game.resources.OSSounds;
	
	import org.flixel.FlxParticle;

	public class OSWater extends OSEmitter
	{
		private var _maxY:Number;
		private var _sound:OSSound;
		private var _right:Boolean;
		
		public function OSWater(X:Number, Y:Number, nbParticles:Number, maxY:Number, right:Boolean)
		{
			super(X, Y, nbParticles);
			_maxY = maxY;
			_right = right;
			
			setYSpeed(-50, 50);
			setGravity(200);
			
			if(right){
				setXSpeed(0, 50);
			}
			else{
				setXSpeed(-50, 0);
			}
			var particle:FlxParticle; 
			for (var i:int = 0; i < getMaxSize() / 2; i++) 
			{
				
				particle = new FlxParticle();
				particle.makeGraphic(2, 2, 0xFF3399FF);
				particle.visible = false;
				addParticle(particle);
				
				particle = new FlxParticle();
				particle.makeGraphic(1, 1, 0xFF3399FF);
				particle.visible = false;
				addParticle(particle);
			}
			
			start(false, 5, .02);
			
			_sound = new OSSound(x, y, 0.05);
			_sound.loadEmbedded(OSSounds.WATERFALL, true);
			add(_sound);
		}
		
		public override function update():void
		{
			for(var i:uint=0;i<_particleEmitter.members.length;i++)
			{
				var p:FlxParticle = _particleEmitter.members[i] as FlxParticle;
				if(p.y >= _maxY)
				{
					p.velocity.x = Math.random() * 100 * (_right ? 1 : -1);
					p.velocity.y = Math.random() * -50 - 10;
				}
			}
			
			super.update();
		}
	}
}